<!DOCTYPE html>
<html>

<head>
    <title>Bootstrap 徽章</title>
    <meta charset="utf-8">
    <!-- 适应移动设备 -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="./css/bootstrap.css">
    <script src="./jquery-3.5.1.min.js"></script>
    <script src="./js/bootstrap.js"></script>
</head>

<body>
    <br>
    <div class="container" style="border: 1px solid red;">
        <a href="#">Mailbox <span class="badge">50</span></a>
    </div>

    <br>
    <div class="container" style="border: 1px solid red;">
        <h2>徽章</h2>
        <p>.badge 类指定未读消息的数量:</p>
        <p><a href="#">收件箱 <span class="badge"></span></a></p>
    </div>

    <br>
    <div class="container" style="border: 1px solid red;">
        <ul class="nav nav-pills" id="u1">
            <li class="active">
                <a href="#">首页
                    <span class="badge">42</span>
                </a>
            </li>
            <li>
                <a href="#">简介</a>
            </li>
            <li>
                <a href="#">消息
                    <span class="badge">3</span>
                </a>
            </li>
        </ul>
        <br>
        <h4>列表导航中的激活状态</h4>
        <ul class="nav nav-pills nav-stacked" style="max-width: 260px;"  id="u2">
            <li class="active">
                <a href="#">
                    <span class="badge pull-right">42</span>首页</a>
            </li>
            <li>
                <a href="#">简介</a>
            </li>
            <li>
                <a href="#">
                    <span class="badge pull-right">3</span>消息
                </a>
            </li>
        </ul>
    </div>

</body>
<script>
     Array.from($('#u1 li a')).forEach(element => {
        element.onclick = function () {
            console.log(element.textContent);
            $('#u1 li.active').removeClass('active');
            element.parentNode.className = 'active';
        }
    });
    Array.from($('#u2 li a')).forEach(element => {
        element.onclick = function () {
            console.log(element.textContent);
            $('#u2 li.active').removeClass('active');
            element.parentNode.className = 'active';
        }
    });
</script>
</html>